package myNewProject.notifier;

import myNewProject.utils.CustomResult;

import java.util.ArrayList;
import java.util.List;

public class NoticeBySOUT implements Notifier {
    @Override
    public void notice(List<CustomResult> parsedResult, String[] keyword) {
        for (String s : keyword) {
            System.out.println("=== === === === ===");
            System.out.println("当前检索关键字：" + s);
            System.out.println("=== === === === ===\n");
            List<CustomResult> filteredResults = filter(parsedResult,s);
            for (CustomResult c : filteredResults){
                System.out.println(c);
            }
        }
        System.out.println("检索完毕！已经全部输出至控制台。");
    }

    @Override
    public void noticeBefore(List<CustomResult> parsedResult, String[] keywords, String timestamp) {

    }

    @Override
    public List<CustomResult> filter(List<CustomResult> parsedResult, String keyword) {
        List<CustomResult> filteredResults = new ArrayList<>();
        for (CustomResult c : parsedResult) {
            if (c.getTitle().contains(keyword)) {
                filteredResults.add(c);
            }
        }
        return filteredResults;
    }
}
